package cc.wsyw126.java.lambda;

import cc.wsyw126.java.model.User;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created by junpeng.yang on 16/12/2.
 */
public class MapAgain {
    public static void main(String[] args) {
        List<Integer> domIds = new ArrayList<>();
        for (int i = 0; i < 100000; i++) {
            domIds.add(i);
        }

        List<User> users = new ArrayList<>();
        Map<String, List<String>> collect = users.stream().collect(Collectors.groupingBy(User::getName, Collectors.mapping(User::getName, Collectors.toList())));

        int[] ints = users.stream().mapToInt(user -> user.getId()).distinct().toArray();


        Map<Integer, String> collect1 = users.stream().collect(Collectors.toMap(User::getId, User::getName, (k, v) -> v));

        int s = domIds.stream().reduce(0, (acc, c) -> acc + c).intValue();
        System.out.println("s = " + s);
        List<Long> domIds2 = new ArrayList<>();
        for (int i = 0; i < 100000; i++) {
            domIds2.add(Long.valueOf(i));
        }
        int sum = domIds2.stream().mapToInt(e -> Math.toIntExact(e)).sum();

        System.out.println("sum = " + sum);
    }
}
